package one.bugu.android.demon.ui.activity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.juefeng.android.framework.view.annotation.LKContentView;
import com.juefeng.android.framework.view.annotation.LKInjectView;

import one.bugu.android.demon.R;

import one.bugu.android.demon.common.MyBaseActivity;

import one.bugu.android.demon.ui.adapter.snatch.FragmentAdapter;

import one.bugu.android.demon.ui.fragment.snatch.MessageFragment;
import one.bugu.android.demon.ui.widget.BaseTopBarView;
import one.bugu.android.demon.util.StatusBarUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 站内信息界面
 */
@LKContentView(R.layout.activity_message)
public class MessageActivity extends MyBaseActivity {

    @LKInjectView(R.id.btbv_message)
    private BaseTopBarView baseTopBarView;

    @LKInjectView(R.id.rl_buying)
    private RelativeLayout rlBuying;

    @LKInjectView(R.id.tv_buying)
    private TextView tvBuying;

    @LKInjectView(R.id.view_buying)
    private View viewBuying;

    @LKInjectView(R.id.rl_buying_end)
    private RelativeLayout rlBuyingEnd;

    @LKInjectView(R.id.tv_end_buying)
    private TextView tvEndBuying;

    @LKInjectView(R.id.view_buying_end)
    private View viewBuyingEnd;

    @LKInjectView(R.id.vp_snatch)
    private ViewPager vpSnatch;

    @Override
    public void initView() {
        super.initView();
        //适配状态栏
        StatusBarUtils.getInstance().setStatusBar("#EEEEEE", this, baseTopBarView, false);
        //默认显示抢购中列表
        setTab(MessageFragment.WARN_MSG);
        //添加页面展示fragment
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(MessageFragment.newInstance(MessageFragment.SYS_MSG));
        fragmentList.add(MessageFragment.newInstance(MessageFragment.WARN_MSG));
        //viewpager适配器初始化
        FragmentAdapter mAdater = new FragmentAdapter(getSupportFragmentManager(), fragmentList);
        vpSnatch.setAdapter(mAdater);
    }

    /**
     * 获取信息详情
     */
    @Override
    protected void initData() {
        super.initData();

    }

    @Override
    protected void initEvent() {
        super.initEvent();
        //返回点击事件
        baseTopBarView.setEventInterface(new BaseTopBarView.EventInterface() {
            @Override
            public void leftOnClick() {
                finish();
            }

            @Override
            public void leftCloseClick() {

            }

            @Override
            public void rightOnClick() {

            }
        });

        rlBuying.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setTab(MessageFragment.WARN_MSG);
            }
        });
        rlBuyingEnd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setTab(MessageFragment.SYS_MSG);
            }
        });
    }

    /**
     * 设置tab按钮状态
     *
     * @param snatchState
     */
    private void setTab(int snatchState) {
        boolean status = snatchState == MessageFragment.WARN_MSG;
        vpSnatch.setCurrentItem(snatchState);
        //抢购状态
        tvBuying.setSelected(status);
        tvBuying.setTextSize(status ? 14 : 14);
        viewBuying.setVisibility(status ? View.VISIBLE : View.GONE);

        //结束状态
        tvEndBuying.setSelected(!status);
        tvEndBuying.setTextSize(!status ? 14 : 14);
        viewBuyingEnd.setVisibility(!status ? View.VISIBLE : View.GONE);
    }
}


